<?php
$this->breadcrumbs = array(
    'Jobs' => array('index'),
    $model->pdid,
);
?>

<?php
$this->renderPartial('_menu', array(
    'model' => $model,
));
?>

<?php
$this->widget('application.extensions.fancybox.EFancyBox', array('target' => 'a.iframe', 'config' => array('width' => 800, 'height' => 600)));
?>

<?php
//加载展示详细信息时候用的css文件
Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl . '/css/styles.css');
if ($model->status == 100) {
    $template = 'Y';
} else {
    $template = 'N';
}
switch ($model->type) {
    case 'O':
        $type = 'Once';
        break;
    case 'S':
        $type = 'Shift';
        break;
    case 'D':
        $type = 'Day';
        break;
    case 'W':
        $type = 'Week';
        break;
    case 'M':
        $type = 'Month';
        break;
    case 'Y':
        $type = 'Year';
        break;
    default :
        $type = 'Once';
}
?>
<h1>View Job #<?php echo $model->pdid; ?></h1>

<table id="yw1" class="detail-view">
    <tbody>
        <tr class="odd">
            <th style="width:15%; text-align:left;">Office</th>
            <td style="width:35%;"><?= $model->user->office ?></td>
            <th style="width:15%; text-align:left;">Code</th>
            <td><?= $model->user->username ?></td>
        </tr>
        <tr class="even">
            <th style="width:15%; text-align:left;">Position</th>
            <td style="width:35%;"><?= $model->user->position ?></td>
            <th style="width:15%; text-align:left;">Name</th>
            <td><?= $model->user->pname ?></td>
        </tr>
        <tr class="odd">
            <th style="width:15%; text-align:left;">Periodic</th>
            <td style="width:35%;"><?= $type ?></td>
            <th style="width:15%; text-align:left;">Time</th>
            <td><?= $model->time ?></td>
        </tr>
        <tr class="even">
            <th style="width:15%; text-align:left;">Job</th>
            <td style="width:35%;"><?= $model->job ?></td>
            <th style="width:15%; text-align:left;">Template</th>
            <td><?= $template ?></td>
        </tr>
    </tbody>
</table>



<?php
$this->widget('zii.widgets.grid.CGridView', array(
    'afterAjaxUpdate' => "function(id,data){ $('a.iframe').fancybox({'width':800,'height':600}); }",
    'id' => 'person-task-grid',
    'dataProvider' => $searchModel->belongSearch($model->pdid),
    'filter' => $searchModel,
    'columns' => array(
        'tcode' => array(
            'name' => 'task.tcode',
            'header' => 'Tcode',
            'headerHtmlOptions' => array('width' => '10%'),
            'htmlOptions' => array('style' => 'text-align:center;')
        ),
        'subcode' => array(
            'name' => 'task.subcode',
            'header' => 'Subcode',
            'headerHtmlOptions' => array('width' => '10%'),
            'htmlOptions' => array('style' => 'text-align:center;')
        ),
        'taskdetail' => array(
            'name' => 'task.taskdetail',
            'header' => 'Task',
			'value'=>'Helper::truncate_utf8_string($data->task->taskdetail,18,false)',
            'headerHtmlOptions' => array('width' => '30%'),
        ),
        'urgency' => array(
            'name' => 'task.urgency',
            'header' => 'Urgency',
            'headerHtmlOptions' => array('width' => '10%'),
            'htmlOptions' => array('style' => 'text-align:center;')
        ),
        'tco' => array(
            'name' => 'task.tco',
            'header' => 'TCO',
            'headerHtmlOptions' => array('width' => '10%'),
            'htmlOptions' => array('style' => 'text-align:center;')
        ),
        'sco' => array(
            'name' => 'task.sco',
            'header' => 'SCO',
            'headerHtmlOptions' => array('width' => '10%'),
            'htmlOptions' => array('style' => 'text-align:center;')
        ),
        'status' => array(
            'name' => 'status',
            'header' => 'Status',
            'headerHtmlOptions' => array('width' => '10%'),
            'htmlOptions' => array('style' => 'text-align:center;')
        ),
        /*
          'dateline',
          'updated',
         */
        array(
            'class' => 'CLinkColumn',
            'header' => '操作', //显示表名称
            'headerHtmlOptions' => array('width' => '10%'),
            'labelExpression' => '详情', //显示名称
            'urlExpression' => 'Yii::app()->createUrl("personTask/popView",array("id"=>$data->ptid))', //显示URL
//            'urlExpression' => 'Yii::app()->createUrl("personTask/view",array("id"=>$data->ptid))', //显示URL
            'linkHtmlOptions' => array('class' => 'iframe'),
            'htmlOptions' => array('style' => 'text-align:center;'),
        ),
        array(
            'class' => 'CCheckBoxColumn',
            'name' => 'tid',
            'id' => 'taskSelect',
            'selectableRows' => 2,
            'footer' => '<button type="button" onclick="GetCheckbox();" >Delete</button>',
            'htmlOptions' => array('style' => 'text-align:center;'),
        ),
    ),
));
?>
<script type="text/javascript">
    /*<![CDATA[*/
    var GetCheckbox = function (){
        var data=new Array();
        $("input:checkbox[name='taskSelect[]']").each(function (){
            if($(this).attr("checked")=='checked'){
                data.push($(this).val());
            }
        });
        if(data.length > 0){
            $.post('<?php echo CHtml::normalizeUrl(array('/personTask/removeTaskAjax')); ?>',{'taskSelect[]':data,'pdid':<?= $model->pdid ?>}, function (data) {
                var ret = $.parseJSON(data);
                if (ret != null && ret.success != null && ret.success) {
                    alert(ret.msg);
                    window.location.href = '<?php echo CHtml::normalizeUrl(array('/personDate/view&id=' . $model->pdid)); ?>';
                }
            });
        }else{
            alert("请选择要删除的关联任务!");
        }
    }
    /*]]>*/
</script>